﻿package mortal.game.view.guildNew.WareHourse
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.component.gconst.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.menu.*;

    public class GuildNewWHItemCell extends GCellRenderer
    {
        private var _isNotMeet:Boolean;
        private var _notMeetCareerEffect:ScaleBitmap;
        private var _item:BaseItem;
        private var _txtStrenLv:BitmapNumberText;

        public function GuildNewWHItemCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._item = UIFactory.getUICompoment(BaseItem, 0, 0, this);
            this._item.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 3);
            this._txtStrenLv = UIFactory.bitmapNumberText(0, 22, "FightInfoNum.png", 12, 15, -1, this);
            this._txtStrenLv.mouseEnabled = false;
            this.doubleClickEnabled = true;
            this.configEventListener(MouseEvent.CLICK, this.onMouseClick);
            this.configEventListener(MouseEvent.DOUBLE_CLICK, this.onDoubleCk);
            this._item.isDragAble = true;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            ItemMenuRegister.unRegister(this._item);
            if (this._notMeetCareerEffect)
            {
                this._notMeetCareerEffect.dispose(param1);
                this._notMeetCareerEffect = null;
            }
            this._item = null;
            if (this._txtStrenLv)
            {
                this._txtStrenLv.dispose(param1);
                this._txtStrenLv = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        private function onMouseClick(event:MouseEvent) : void
        {
            if (this.data == null)
            {
                return;
            }
            return;
        }// end function

        private function onDoubleCk(event:MouseEvent) : void
        {
            if (this.data == null || this._item.itemData == null)
            {
                return;
            }
            var _loc_2:* = this._item.itemData as ItemData;
            var _loc_3:* = ItemMenuConst.getEnabeldAttri(ItemMenuConst.GuildWareHouseItem, this._item.itemData);
            if (_loc_3 && _loc_3.length > 0)
            {
                ItemMenuConst.opearte(_loc_3.getItemAt(0)["label"], _loc_2);
            }
            return;
        }// end function

        public function set isNotMeetCarrer(param1:Boolean) : void
        {
            this._isNotMeet = param1;
            if (this._isNotMeet)
            {
                if (!this._notMeetCareerEffect)
                {
                    this._notMeetCareerEffect = ResourceConst.getScaleBitmap(ImagesConst.PackDisable);
                    this.addChild(this._notMeetCareerEffect);
                    this._notMeetCareerEffect.width = 36;
                    this._notMeetCareerEffect.height = 36;
                    this._notMeetCareerEffect.x = 3;
                    this._notMeetCareerEffect.y = 2;
                }
            }
            if (this._notMeetCareerEffect)
            {
                this._notMeetCareerEffect.visible = this._isNotMeet;
                if (this._isNotMeet)
                {
                    this.addChild(this._notMeetCareerEffect);
                }
            }
            return;
        }// end function

        override public function get data() : Object
        {
            return super.data;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:ItemData = null;
            super.data = param1;
            this.isNotMeetCarrer = false;
            ItemMenuRegister.unRegister(this._item);
            if (param1 == null)
            {
                this._item.itemData = null;
                return;
            }
            if (param1 is ItemData)
            {
                _loc_2 = param1 as ItemData;
            }
            else if (param1 is ItemInfo)
            {
                _loc_2 = new ItemData(param1.code);
            }
            else if (param1 is SPlayerItem)
            {
                _loc_2 = new ItemData(param1 as SPlayerItem);
            }
            else
            {
                _loc_2 = null;
            }
            this._item.itemData = _loc_2;
            if (this._item.itemData)
            {
                this.isNotMeetCarrer = !ItemsUtil.isFitCarrer(_loc_2);
                ItemMenuRegister.register(this._item, this._item.itemData, ItemMenuConst.getEnabeldAttri(ItemMenuConst.GuildWareHouseItem, this._item.itemData));
            }
            this.updateStrengLevel();
            return;
        }// end function

        private function updateStrengLevel() : void
        {
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            var _loc_3:String = null;
            this._txtStrenLv.text = "";
            if (this._item && this._item.itemData)
            {
                if (ItemsUtil.isEquip(this._item.itemData))
                {
                    _loc_1 = this._item.itemData.extInfo == null ? (0) : (this._item.itemData.extInfo.strengthen);
                    _loc_2 = this._item.itemData.extInfo == null ? (0) : (this._item.itemData.extInfo.currentStrengthen);
                    if (_loc_1 == 0 && _loc_2 == 0)
                    {
                        _loc_3 = "";
                    }
                    else
                    {
                        _loc_3 = "+" + _loc_1;
                    }
                    this._txtStrenLv.text = _loc_3;
                }
                else if (ItemsUtil.isOtherEquip(this._item.itemData) && this._item.itemData.itemInfo.itemLevel)
                {
                    this._txtStrenLv.text = "+" + this._item.itemData.itemInfo.itemLevel;
                }
                this._txtStrenLv.x = this.width - this._txtStrenLv.width - 6;
                this._txtStrenLv.y = this.height - this._txtStrenLv.height - 8;
            }
            else
            {
                this._txtStrenLv.text = "";
            }
            return;
        }// end function

    }
}
